package com.yehun.utils;


import com.yehun.config.SpringMvcActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Genius on 2017/4/7 0007.
 */
public class RequestUtils {

    /**
     * 获取客户端ip
     */
    public static String getIp() {
        HttpServletRequest request = SpringMvcActionContext.getRequest();
        String ip = request.getHeader("X-FORWARDED-FOR");
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("PRoxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

}
